package cn.gson.springboot.controllers;



import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mysql.cj.xdevapi.JsonArray;
import cn.gson.springboot.model.mapper.MedicalMapper;
import cn.gson.springboot.model.mapper.MlossMapper;
import cn.gson.springboot.model.pojos.CureCostPx;
import cn.gson.springboot.model.pojos.CurePx;
import cn.gson.springboot.model.pojos.DepartmentsPx;
import cn.gson.springboot.model.pojos.DrugsYk;
import cn.gson.springboot.model.pojos.ExamineItem;
import cn.gson.springboot.model.pojos.GhlxPx;
import cn.gson.springboot.model.pojos.MedicalCardPx;
import cn.gson.springboot.model.pojos.MedicalNoticePx;
import cn.gson.springboot.model.pojos.MedicalNoticexqPx;
import cn.gson.springboot.model.pojos.MzcostDetail;
import cn.gson.springboot.model.pojos.OutpatientRecord;
import cn.gson.springboot.model.pojos.PrescriptionDetailsPx;
import cn.gson.springboot.model.pojos.PrescriptionPx;
import cn.gson.springboot.model.pojos.RegisteredPx;
import cn.gson.springboot.model.pojos.User;
import cn.gson.springboot.model.service.Arrangeclassserivce;
import cn.gson.springboot.model.service.Cureserivce;
import cn.gson.springboot.model.service.DepartmentsPxserivce;
import cn.gson.springboot.model.service.DrugsYkService;
import cn.gson.springboot.model.service.Ghlxserivce;
import cn.gson.springboot.model.service.MedicalService;
import cn.gson.springboot.model.service.Outpatientrecordsservice;
import cn.gson.springboot.model.service.Registeredserivce;
import cn.gson.springboot.model.service.Userservice;
import cn.gson.springboot.model.service.ypserivce;
import cn.gson.springboot.model.vo.CurecostVO;
import cn.gson.springboot.model.vo.ExamineVO;
import cn.gson.springboot.model.vo.MedicalNoticeVO;
import cn.gson.springboot.model.vo.PrescriptionVO;

@Controller
public class GhlxController {
	private Integer sjd;//用来指定早中晚班次id
	//挂号类型serivce
	@Autowired
	private Ghlxserivce  gs;
	//医疗卡mapper
	@Autowired
	private MedicalMapper Mp;
	
	//排班serivce
	@Autowired
	private Arrangeclassserivce  AS;
	
	//挂号记录serivce
	@Autowired
	private Registeredserivce regs;
	
	//医疗卡serivce
	@Autowired
	private MedicalService  ms;
	
	@Autowired
	private ypserivce ys;
	
	//医疗项目service
	@Autowired
	private Cureserivce cs;
	
	//挂号界面
	@RequestMapping("registered-px")
	public void regiStered(Model model) {
		
			
	}
	//查询所有挂号类型
	@RequestMapping("ghlx")
	@ResponseBody
	public JSONArray ghlx() {
		Date  date=new Date();
		int sss=date.getHours();//取到时
		if(sss>17) {
			JSONArray cxjz = gs.cxjz();
			return cxjz;
		}else {
			JSONArray finghlx =gs.finghlx();
			return  finghlx;
		}
		
	}
	
	
	//根据挂号类型id查询挂号金额
	@RequestMapping("idghje")
	@ResponseBody
	public JsonArray idghje(Integer ghlx_id) {
		JsonArray idje=gs.idghje(ghlx_id);
		return idje;
	}
	
	
	
	//根据科室查询上班医生
	@RequestMapping("cxsbys")
	@ResponseBody
	public JSONArray cxsbys(Integer ksid){
		Date  date=new Date();
		int sss=date.getHours();//取到时
		SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd"); 
		 String sj=format.format(date);
		 if(sss>17){
			 sjd=3; 
			 JSONArray cxsbys = AS.cxsbys(ksid,sjd);
			 return cxsbys;
		 }else {
			 if(sss>8 && sss<12) {
				 //早 
				 sjd=1;
				
			 }else if(sss>=14 && sss<17){
				 //中
				 sjd=2;
				
			 }else if(sss>=17 && sss<24) {
				 //晚
				sjd=3;
				
			 }else if(sss>=24 && sss<8) {
				 //夜
				sjd=5;
				
			 } 
		 }
		 JSONArray cxsbys = AS.cxsbys(ksid,sjd);
		 System.out.println(cxsbys);
		 return cxsbys;
		
		 	
	
	}
	//根据科室查询上班护士
		@RequestMapping("cxsbhs")
		@ResponseBody
		public JSONArray cxsbhs(Integer ksid){
			Date  date=new Date();
			int sss=date.getHours();//取到时
			SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd"); 
			 String sj=format.format(date);
			 if(sss>17){
				 sjd=3; 
				 JSONArray cxsbhs = AS.cxsbhs(ksid,sjd);
				 return cxsbhs;
			 }else {
				 if(sss>8 && sss<12) {
					 //早 
					 sjd=1;
					
				 }else if(sss>=14 && sss<17){
					 //中
					 sjd=2;
					
				 }else if(sss>=17 && sss<24) {
					 //晚
					sjd=3;
					
				 }else if(sss>=24 && sss<8) {
					 //夜
					sjd=5;
					
				 } 
			 }
			 JSONArray cxsbhs = AS.cxsbhs(ksid,sjd);
			 System.out.println(cxsbhs);
			 return cxsbhs;
			
			 	
		
		}
	
	
	//根据医疗卡号查询病人信息
	@RequestMapping("yikcx")
	@ResponseBody
	public JSONArray ylkcx(String mzcard_id){
		JSONArray idmedical = Mp.idmedical(mzcard_id);
			System.out.println("根据医疗卡号查询病人信息--------"+idmedical);
			return idmedical;
		
		
	}
	
	//新增挂号记录
	@PostMapping("xzghjl")
	@ResponseBody
	public String addregistered(String mecardNumber,Integer userId,BigDecimal kzfy
			,BigDecimal ghlx_money,Integer departments_id,Integer ghlx_id,BigDecimal ghzj,
			BigDecimal ghzl,BigDecimal ghss,HttpSession session){
		try {
			User user = (User)session.getAttribute("user");
			String userName=user.getUserName();
			gs.addregistered(mecardNumber, userId, kzfy, ghlx_money, departments_id, ghlx_id, ghzj, ghzl, ghss,userName);
			return "1";
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return "0";
			
		}
		
		
	}
	
	//=====查询所有挂号记录
	@RequestMapping("px-jilu")
	@ResponseBody
	public Map<String, Object> pxjilu(int page,int rows) {
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				JSONArray ghjl = AS.ghjl();
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", ghjl);//封装当前页的内容
				return map;
	}
	
	
		/*<!-- 根据医生id查询挂该医生的病人 -->*/
		@RequestMapping("ysidcbr")
		@ResponseBody
		public Map<String, Object> ysidcbr(int page,int rows,HttpSession session,String mecard_number) {
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					User user = (User)session.getAttribute("user");
					JSONArray jueSe = gs.jueSe(user.getUserId());
					Integer aa = 0;
					for (int i = 0; i < jueSe.size(); i++) {
						JSONObject object =jueSe.getJSONObject(i);
						if((Integer)object.get("role_id")==4) {
							aa=4;
						}
					}
					if(aa==4) {
						JSONArray ysidcbr = AS.ysidcbr(mecard_number);//这里定的是医生id的死值
						//进行数据格式转换和封装
						Map<String,Object> map = new HashMap<>();
						map.put("total", pg.getTotal());//封装总记录数
						map.put("rows", ysidcbr);//封装当前页的内容
						return map;
					}else{
						
						JSONArray ysidcbrer = AS.ysidcbrer(user.getUserId(),mecard_number);//这里定的是医生id的死值
						//进行数据格式转换和封装
						Map<String,Object> map = new HashMap<>();
						map.put("total", pg.getTotal());//封装总记录数
						map.put("rows", ysidcbrer);//封装当前页的内容
						return map;
					}
					
					
					
						
					
		}
		
		//根据病人医疗卡主键查询用户信息 -->
		@PostMapping("zjmedical")
		@ResponseBody
		public JSONArray zjmedical(Integer mzcard_id,Integer outpatient_id){
				JSONArray idmedical =ms.zjmedical(mzcard_id);
//				System.out.println(idmedical);
//				//在这里医生添加完病人,就要立马修改病人挂号状态改为以	
//				RegisteredPx idreg = regs.idreg(outpatient_id);
//					idreg.setGhzt(new BigDecimal(0));
//					regs.addregistered(idreg);
//					System.out.println("修改成功");
				return idmedical;
		}
		
		//查询中药
		@RequestMapping("zhongyao")
		@ResponseBody
		public JSONArray zhongyao() {
				JSONArray zhongyao = ys.zhongyao();
				return zhongyao;
		}
		
		//根据药品名字查询中药
		@PostMapping("nameZhongyao")
		@ResponseBody
		public JSONArray nameZhongyao(String drug_name) {
			if(drug_name!=null) {
				if(drug_name.equals("")) {
					drug_name=null;
				}
			}
				JSONArray nameZhongyao = ys.nameZhongyao(drug_name);
				return nameZhongyao;
		} 
		
		//查询西药
		@RequestMapping("xiyao")
		@ResponseBody
		public JSONArray xiyao() {
			JSONArray xiyao = ys.xiyao();
				return xiyao;
		}
		
		//根据药品名字查询西药
		@PostMapping("nameXiyao")
		@ResponseBody
		public JSONArray nameXiyao(String drug_name) {
			if(drug_name!=null) {
				if(drug_name.equals("")) {
					drug_name=null;
				}
			}
				JSONArray nameXiyao = ys.nameXiyao(drug_name);
				return nameXiyao;
		}
		
		//查询所有医疗项目
		@RequestMapping("ylxm")
		@ResponseBody
		public JSONArray ylxm(){
			JSONArray findcure = cs.findcure();
			return findcure;
		}
		
		//<!-- 根据医疗项目名字查询医疗项目 -->
		@PostMapping("nameYiLiao")
		@ResponseBody
		public JSONArray nameYiLiao(String cure_name){
			if(cure_name!=null) {
				if(cure_name.equals("")) {
					cure_name=null;
				}
			}
			JSONArray nameYiLiao = cs.nameYiLiao(cure_name);
			return nameYiLiao;
		}
		
		/*<!--根据门诊号查询病人挂号信息  -->*/
		@RequestMapping("menzh")
		@ResponseBody
		public JSONArray menzh(Integer outpatient_id){
			 JSONArray menzh = ms.menzh(outpatient_id);
			 System.out.println(menzh);
			return menzh;
		}
		
		
		//新增病历
		@PostMapping("addbl")
		@ResponseBody
		public String  addbl(Integer outpatient_id, String medical_symptoms,
				BigDecimal medical_weight,BigDecimal medical_temperature,String medical_disease,HttpSession session) {
			User user = (User)session.getAttribute("user");
			String userName=user.getUserName();
			gs.addbl(outpatient_id, medical_symptoms, medical_weight, medical_temperature, medical_disease,userName);
			try {
				return "1";
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
		}
		
		//查看所有病历记录
		@RequestMapping("findout")
		@ResponseBody
		public Map<String, Object> findout(int page,int rows) {
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					JSONArray findout = gs.findout();//这里定的是医生id的死值
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", findout);//封装当前页的内容
					return map;
		}
		//根据医疗卡门诊号查询病历
		@PostMapping("medfindout")
		@ResponseBody
		public Map<String, Object> medfindout(int page,int rows,String mecard_number) {
			System.out.println(mecard_number);
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					if(mecard_number!=null) {
						if(mecard_number.equals("")) {
							mecard_number=null;
						}
					}
					JSONArray findout = gs.medfindout(mecard_number);
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", findout);//封装当前页的内容
					return map;
		}
		
		
		
		
		//查询所有未交费的医疗项目单
		@RequestMapping("findCrueCost")
		@ResponseBody
		public JSONArray findCrueCost() {
			JSONArray findCrueCost = AS.findCrueCost();
			return findCrueCost;
		}
		
		//查询所有以交费的医疗项目单
		@RequestMapping("findCrueCosty")
		@ResponseBody
		public JSONArray findCrueCosty() {
					JSONArray findCrueCosty = AS.findCrueCosty();
					return findCrueCosty;
		}
		
		//根据医疗卡号查询所有未交费的医疗项目单
		@PostMapping("medfindCrueCost")
		@ResponseBody
		public Map<String, Object> medfindCrueCost(int page,int rows,String mecard_number) {
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
						if(mecard_number!=null) {
							if(mecard_number.equals("")) {
								mecard_number=null;
							}
						}
					JSONArray medfindCrueCost = AS.medfindCrueCost(mecard_number);
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", medfindCrueCost);//封装当前页的内容
					return map;
		}
		
		//根据医疗卡号查询所有以交费的医疗项目单
		@PostMapping("medfindCrueCosty")
		@ResponseBody
		public Map<String, Object> medfindCrueCosty(int page,int rows,String mecard_number) {
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
						if(mecard_number!=null) {
							if(mecard_number.equals("")) {
								
								mecard_number=null;
							}
						}
					JSONArray medfindCrueCosty = AS.medfindCrueCosty(mecard_number);
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", medfindCrueCosty);//封装当前页的内容
					return map;
		}
		
		/* 通过医疗项目主表id查询详表 */
		@PostMapping("idMzcostDetails")
		@ResponseBody
		public JSONArray idMzcostDetails(Integer cure_cost_id) {
			JSONArray idMzcostDetails = AS.idMzcostDetails(cure_cost_id);
			return idMzcostDetails;
		}
		
	/*//新增医疗项目收费记录
		public JSONArray add() {
			gs.addCureCostPx();
		}
		*/
		
		//查看体检项目
		@RequestMapping("findexamin")
		@ResponseBody
		public JSONArray findExamin(){
			JSONArray findexamin= gs.findexamin(null);
			return findexamin;
		}
		
		//根据名字查看查看体检项目
		@RequestMapping("tiJianName")
		@ResponseBody
		public JSONArray tiJianName(String examine_item_name){
				if(examine_item_name!=null) {
					if(examine_item_name.equals("")) {
						examine_item_name=null;
					}
				}
					JSONArray tiJianName= gs.tiJianName(examine_item_name);
					return tiJianName;
		}
		
		@RequestMapping("xztjtzjl")
		@ResponseBody
		public String addExamineR(ExamineVO xo) {
			try {
				gs.addExamineR(xo);
				return "1";
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
		}
		
		
		
		//门诊药方主从表添加
		@RequestMapping("addyf")
		@ResponseBody
		public  String  addyf(PrescriptionVO po,HttpSession session) {
			try {
				User user = (User)session.getAttribute("user");
				String userName = user.getUserName();
				gs.addyf(po,userName);
				return "1";
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
		}
		
		//医疗项目主从表新增
		@RequestMapping("addysxm")
		@ResponseBody
		public String addysxm(CurecostVO vo,HttpSession session) {
			try {
				User user = (User)session.getAttribute("user");
				String userName = user.getUserName();
				gs.addysxm(vo,userName);
				return "1";
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
			
		}
		
		//查询所有未交费的门诊药方
		@RequestMapping("findwjf")
		@ResponseBody
		public Map<String, Object> findwjf(int page,int rows) {
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray findwjf = gs.findwjf();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", findwjf);//封装当前页的内容
			return map;
		}
		
		//查询所有以交费的门诊药方
				@RequestMapping("finDwjfy")
				@ResponseBody
				public Map<String, Object> finDwjfy(int page,int rows) {
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					JSONArray finDwjfy = gs.finDwjfy();
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", finDwjfy);//封装当前页的内容
					return map;
				}
		
		//根据医疗卡号查询所有未交费的门诊药方
		@RequestMapping("medfindwjf")
		@ResponseBody
		public Map<String, Object> medfindwjf(int page,int rows,String mecard_number) {
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					if(mecard_number!=null) {
						if(mecard_number.equals("")) {
							mecard_number=null;
						}
					}
					JSONArray medfindwjf = gs.medfindwjf(mecard_number);
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", medfindwjf);//封装当前页的内容
					return map;
		}
		
		//根据医疗卡号查询以交费的门诊药方
		@RequestMapping("medfindwjfy")
		@ResponseBody
		public Map<String, Object> medfindwjfy(int page,int rows,String mecard_number) {
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				if(mecard_number!=null) {
					if(mecard_number.equals("")) {
						mecard_number=null;
					}
				}
				JSONArray medfindwjfy = gs.medfindwjfy(mecard_number);
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", medfindwjfy);//封装当前页的内容
				return map;
		}
		
		
		
		//根据药方主表id查询详表药品信息  
		@PostMapping("idFindxq")
		@ResponseBody
		public JSONArray idFindxq(Integer prescription_id) {
			JSONArray idFindxq = gs.idFindxq(prescription_id);
			return idFindxq;
		}
		
	/*	//查询所有未交费的体检
		@RequestMapping("findTjwjf")
		@ResponseBody
		public Map<String, Object> findTjwjf(int page,int rows) {
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray findTjwjf = gs.findTjwjf();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", findTjwjf);//封装当前页的内容
			return map;
		}
		*/
		
		/*<!--  根据体检主表id查询体检详情项目-->*/
		@PostMapping("idTijian")
		@ResponseBody
		public JSONArray idTijian(Integer medical_notice_id) {
			JSONArray idTijian = gs.idTijian(medical_notice_id);
			return idTijian;
		}
		
		//新增治疗项目收费记录
		@RequestMapping("addylxm")
		@ResponseBody
		public String addylxm(Integer outpatient_id,Integer
				cure_cost_id,BigDecimal charge_xmjze,BigDecimal 
				xmprescription_ss,BigDecimal xmprescription_zl,
				BigDecimal xmprescription_yh,BigDecimal xmprescription_ys,HttpSession session){
					try {
						User user = (User)session.getAttribute("user");
						String userName = user.getUserName();
						gs.addylxm(outpatient_id, cure_cost_id, charge_xmjze, xmprescription_ss, xmprescription_zl, xmprescription_yh, xmprescription_ys,userName);
						return "1";
					} catch (Exception e) {
						// TODO: handle exception
						e.printStackTrace();
						return "0";
					}
				
			
		}
		
		//新增药方收费记录
		@RequestMapping("addyfsfjl")
		@ResponseBody
		public 	String   addyfsfjl(HttpSession  session,Integer outpatient_id,Integer prescription_id,
				BigDecimal prescription_ys,BigDecimal prescription_ss,
				BigDecimal prescription_zl,BigDecimal prescription_yh,String prescription_name){
			try {
				User user = (User)session.getAttribute("user");
				String userName = user.getUserName();
				gs.addyfsfjl(outpatient_id, prescription_id, prescription_ys, prescription_ss, prescription_zl, prescription_yh, prescription_name,userName);
				return "1";
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
		}
		
		/*//新增体检收费记录
		@RequestMapping("addtjsfjl")
		@ResponseBody
		public String addtjsfjl(Integer outpatient_id,Integer medical_notice_id,
				BigDecimal tjsf_zje,BigDecimal tj_ys,
				BigDecimal tj_ss,BigDecimal tj_yh,BigDecimal tj_zl){
				try {
					gs.addtjsfjl(outpatient_id, medical_notice_id, tjsf_zje, tj_ys, tj_ss, tj_yh, tj_zl);
						return "1";
				} catch (Exception e) {
					// TODO: handle exception
						return "0";
				}
			
		}*/
		
		@RequestMapping("addtjsfjl")
		@ResponseBody
		public String addtjsfjl(Integer examine_id,
				BigDecimal tjsf_zje,BigDecimal tj_ys,
				BigDecimal tj_ss,BigDecimal tj_yh,BigDecimal tj_zl,HttpSession session){
				try {
					User user = (User)session.getAttribute("user");
					String userName = user.getUserName();
					gs.addtjsfjl(examine_id,tjsf_zje, tj_ys, tj_ss, tj_yh, tj_zl,userName);
						return "1";
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
						return "0";
				}
			
		}
		
		//<!-- 查询所有药方药方收费记录 -->
		@RequestMapping("findyfchanger")
		@ResponseBody
		public Map<String, Object> findyfchanger(int page,int rows) {
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray findyfchanger = gs.findyfchanger();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", findyfchanger);//封装当前页的内容
			return map;
		}
		
		//<!-- 根据医疗卡号查询药方药方收费记录 -->
		@PostMapping("medfindyfchanger")
		@ResponseBody
		public Map<String, Object> findyfchanger(int page,int rows,String mecard_number) {
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
				if(mecard_number!=null){
					if(mecard_number.equals("")) {
						mecard_number=null;
					}
				}
			JSONArray medfindyfchanger = gs.medfindyfchanger(mecard_number);
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", medfindyfchanger);//封装当前页的内容
			return map;
		}	
		
		
		
		
		
		//查询所有体检缴费记录
		@RequestMapping("findtjsfjl")
		@ResponseBody
		public  Map<String,Object> findtjsfjl(int page,int rows){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray findtjsfjl = gs.findtjsfjl();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", findtjsfjl);//封装当前页的内容
			return map;
		}
		
		//根据医疗卡号查询所有体检缴费记录
		@PostMapping("medfindtjsfjl")
		@ResponseBody
		public  Map<String,Object> medfindtjsfjl(int page,int rows,Integer examine_id){
				//进行分页
				Page<Object> pg = PageHelper.startPage(page, rows);
				if(examine_id!=null) {
					if(examine_id.equals("")) {
						examine_id=null;
					}
				}
				JSONArray medfindtjsfjl = gs.medfindtjsfjl(examine_id);
				//进行数据格式转换和封装
				Map<String,Object> map = new HashMap<>();
				map.put("total", pg.getTotal());//封装总记录数
				map.put("rows", medfindtjsfjl);//封装当前页的内容
				return map;
		}
		
		//体检未交费收费 
		@RequestMapping("djdl")
		@ResponseBody
		public  Map<String,Object> djdl(int page,int rows){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray djdl = gs.djdl();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", djdl);//封装当前页的内容
			return map;
		}
		
		//体检以交费收费 
		@RequestMapping("djdly")
		@ResponseBody
		public  Map<String,Object> djdly(int page,int rows){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page, rows);
			JSONArray djdly = gs.djdly();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", djdly);//封装当前页的内容
			return map;
		}
		
		
		//根据医疗卡号未交费体检收费体检项目单 
		@RequestMapping("carddjdl")
		@ResponseBody
		public  Map<String,Object> carddjdl(int page,int rows,Integer  examine_id){
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					if(examine_id!=null) {
						if(examine_id.equals("")) {
							examine_id=null;
						}
					}
					JSONArray carddjdl = gs.carddjdl(examine_id);
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", carddjdl);//封装当前页的内容
					return map;
		}
		
		//根据体检以交费体检收费体检项目单 
		@RequestMapping("carddjdly")
		@ResponseBody
		public  Map<String,Object> carddjdly(int page,int rows,String mecard_number){
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					if(mecard_number!=null) {
						if(mecard_number.equals("")) {
							mecard_number=null;
						}
					}
					JSONArray carddjdly = gs.carddjdly(mecard_number);
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", carddjdly);//封装当前页的内容
					return map;
		}
		
		
		
		//查询所有医疗项目缴费记录
		@RequestMapping("findxmsfjl")
		@ResponseBody
		public JSONArray findexamin(){ 
			JSONArray findxmsfjl = gs.findxmsfjl(); 
			return findxmsfjl;
		}
		
		//根据医疗卡号查询所有医疗项目缴费记录
		@PostMapping("mefindxmsfjl")
		@ResponseBody
		public  Map<String,Object> mefindxmsfjl(int page,int rows,String mecard_number){
					//进行分页
					Page<Object> pg = PageHelper.startPage(page, rows);
					if(mecard_number!=null) {
						if(mecard_number.equals("")) {
							mecard_number=null;
						}
					}
					JSONArray mefindxmsfjl = gs.mefindxmsfjl(mecard_number);
					//进行数据格式转换和封装
					Map<String,Object> map = new HashMap<>();
					map.put("total", pg.getTotal());//封装总记录数
					map.put("rows", mefindxmsfjl);//封装当前页的内容
					return map;
		}
		
		///*<!-- 根据药方主表id查询寻该条的收费情况打印票据 -->*/
		@PostMapping("ypiddapj")
		@ResponseBody
		public JSONArray ypiddapj(Integer prescription_id) {
			if(prescription_id!=null) {
				JSONArray ypiddapj = gs.ypiddapj(prescription_id);
				return ypiddapj;
			}else {
				return null;
			}
			
		}
		//根据体检费用主表查询体检收费情况 -->
		@PostMapping("tjidDapj")
		@ResponseBody
		public JSONArray tjidDapj(Integer examine_id) {
			if(examine_id!=null) {
				JSONArray tjidDapj = gs.tjidDapj(examine_id);
				return tjidDapj;
			}else {
				return null;
			}
			
		}
		
		//治疗项目打印票据-->
		@PostMapping("xmidDpj")
		@ResponseBody
		public  JSONArray xmidDpj(Integer cure_cost_id) {
				JSONArray xmidDpj = gs.xmidDpj(cure_cost_id);
				return xmidDpj;
		}
		
		 //根据体检登记主表id查询详表 -->
		@PostMapping("idtjdl")
		@ResponseBody
		public JSONArray idtjdl(Integer examine_id) {
				JSONArray idtjdl = gs.idtjdl(examine_id);
				return idtjdl;
		}
		
		//查询所有需要退费的药单记录
		@RequestMapping("yaofangtuifei")
		@ResponseBody
		public  Map<String,Object> yaofangtuifei(int page,int rows){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page,rows);
			JSONArray yaofangtuifei = gs.yaofangtuifei();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", yaofangtuifei);//封装当前页的内容
			return map;
		}
		//退药药单详情
		@PostMapping("tycxq")
		@ResponseBody
		public JSONArray tycxq(Integer return_id){
				JSONArray tycxq = gs.tycxq(return_id);
				return tycxq;
		}
		
		//根据医疗卡卡号查询挂号记录 -->
		@RequestMapping("medidgh")
		@ResponseBody
		public  Map<String,Object> medidgh(int page,int rows,String mecard_number){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page,rows);
			JSONArray medidgh = AS.medidgh(mecard_number);
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", medidgh);//封装当前页的内容
			return map;
		}
		
		//<!-- 根据医生id和医疗卡号查询挂该医生的病人-->
		@PostMapping("ysidheykkh")
		@ResponseBody
		public JSONArray ysidheykkh(Integer user_id,String mecard_number,HttpSession session){
			User user = (User)session.getAttribute("user");
			Integer  userid = user.getUserId();
			JSONArray ysidheykkh = AS.ysidheykkh(userid, mecard_number);
			return ysidheykkh;
		}
		
		//<!-- 门诊查询体检结果查询 -->
		@RequestMapping("mztjjg")
		@ResponseBody
		public  Map<String,Object> mztjjg(int page,int rows){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page,rows);
			JSONArray mztjjg =gs.mztjjg();
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", mztjjg);//封装当前页的内容
			return map;
		}
		
		//<!-- 根据医疗卡号查询体检结果查询 -->
		@PostMapping("mztjjgYl")
		@ResponseBody
		public  Map<String,Object> mztjjgYl(int page,int rows,String mecard_number){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page,rows);
			if(mecard_number!=null) {
				if(mecard_number.equals("")) {
					mecard_number=null;
				}
			}
			JSONArray mztjjgYl =gs.mztjjgYl(mecard_number);
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", mztjjgYl);//封装当前页的内容
			return map;
		}
		
		//<!-- 根据体检号查询体检医生和结果 -->
		@PostMapping("tjhcJg")
		@ResponseBody
		public JSONArray tjhcJg(Integer examine_id) {
			if(examine_id!=null) {
				JSONArray tjhcJg = gs.tjhcJg(examine_id);
				return tjhcJg;
			}else {
				return null;
			}
			
		}
		
		
		//<!-- 根据体检号查询体检医生和结果二 -->
		@PostMapping("tjhcJgEr")
		@ResponseBody
		public JSONArray tjhcJgEr(Integer examine_id) {
				JSONArray tjhcJgEr = gs.tjhcJgEr(examine_id);
				return tjhcJgEr;
		}
		
		
		//新增住院通知记录
		@RequestMapping("addhos")
		@ResponseBody
		public String addhos(Integer mzcard_id,HttpSession session){
				try {
					User user = (User)session.getAttribute("user");
					String userName = user.getUserName();
						gs.addhos(mzcard_id,userName);
						return "1";
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
						return "0";
						
				}
			
		}
		
		//查询所有班次
		@RequestMapping("BcAll")
		@ResponseBody
		public  JSONArray  BcAll() {
				JSONArray bcAll = gs.BcAll();
				return bcAll;
		}
		
		
		
		//查询所有医生
		@RequestMapping("YsAll")
		@ResponseBody
		public  JSONArray YsAll() {
			JSONArray ysAll = gs.YsAll();
			return ysAll;
		}
		
		
		//新增排班记录
		@PostMapping("addPb")
		@ResponseBody
		public String  addPb(Integer departments_id,Integer arrange_classes_id,Integer user_id,String sj) {
			try {
					Date datee=new Date(sj);
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
					String dateString = formatter.format(datee);
					JSONArray scheduLing = gs.ScheduLing(user_id,dateString);
					
				if(scheduLing.size()>0){
					return "2";
				}else{
					gs.addPb(departments_id, arrange_classes_id,user_id,sj);
					return "1";
				}	
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "0";
			}
		}
		
		
		//<!--根据科室编号查询改科室下的所有医生 -->
		@RequestMapping("KscYs")
		@ResponseBody
		public  JSONArray  KscYs(Integer departments_id) {
			JSONArray kscYs=gs.KscYs(departments_id);
			return 	kscYs;
			
		}
		
		//查询所有排班记录
		@RequestMapping("PbAll")
		@ResponseBody
		public  Map<String,Object> PbAll(int page,int rows,String user_name){
			//进行分页
			Page<Object> pg = PageHelper.startPage(page,rows);
			JSONArray PbAll =gs.PbAll(user_name);
			//进行数据格式转换和封装
			Map<String,Object> map = new HashMap<>();
			map.put("total", pg.getTotal());//封装总记录数
			map.put("rows", PbAll);//封装当前页的内容
			
			return map;
		}
		
		//查询所有护士
		@RequestMapping("HsAll")
		@ResponseBody
		public JSONArray HsAll() {
			JSONArray hsAll = gs.HsAll();
			
			return hsAll;
		}
		
		//门诊查询所有科室
		@RequestMapping("findMzks")
		@ResponseBody
		public JSONArray findMzks(Model modle) {
			JSONArray findMzks = gs.findMzks();
			modle.addAttribute("mzks", findMzks);
			return findMzks;
		}
		
		//<!-- 根据系统时间查询门诊部上早班的医生 -->
		@PostMapping("mzYszb")
		@ResponseBody
		public JSONArray mzYszb(Integer departments_id) {
			JSONArray mzYszb = gs.mzYszb(departments_id);
			System.out.println(mzYszb);
			return mzYszb;
		}
		//<!-- 根据系统时间查询门诊部上中班的医生 -->
		@PostMapping("mzYshb")
		@ResponseBody
		public JSONArray mzYshb(Integer departments_id) {
			JSONArray mzYshb = gs.mzYshb(departments_id);
			return mzYshb;
		}
		//<!-- 根据系统时间查询门诊部上晚班的医生 -->
		@PostMapping("mzYswb")
		@ResponseBody
		public JSONArray mzYswb(Integer departments_id) {
			JSONArray mzYswb = gs.mzYswb(departments_id);
			return mzYswb;
		}
		
		//<!-- 根据系统时间查询门诊部上夜班的医生 -->
		@PostMapping("mzYsyb")
		@ResponseBody
		public JSONArray mzYsyb(Integer departments_id) {
			JSONArray mzYsyb = gs.mzYsyb(departments_id);
			return mzYsyb;
		}
		
		
		//<!-- 根据系统时间查询门诊部上早班的护士 -->
		@PostMapping("mzHszb")
		@ResponseBody
		public JSONArray mzHszb(Integer departments_id) {
			JSONArray mzHszb = gs.mzHszb(departments_id);
			return mzHszb;
		}
		//<!-- 根据系统时间查询门诊部上中班的护士 -->
		@PostMapping("mzHshb")
		@ResponseBody
		public JSONArray mzHshb(Integer departments_id) {
			JSONArray mzHshb = gs.mzHshb(departments_id);
			return mzHshb;
		}
		//<!-- 根据系统时间查询门诊部上晚班的护士 -->
		@PostMapping("mzHswb")
		@ResponseBody
		public JSONArray mzHswb(Integer departments_id) {
			JSONArray mzHswb = gs.mzHswb(departments_id);
			return mzHswb;
		}
		
		//<!-- 根据系统时间查询门诊部上夜班的护士 -->
		@PostMapping("mzHsyb")
		@ResponseBody
		public JSONArray mzHsyb(Integer departments_id) {
			JSONArray mzHsyb = gs.mzHsyb(departments_id);
			return mzHsyb;
		}
		
		
		//<!-- 根据上班时间查询住院上班医生护士 -->
		@PostMapping("sbShiJian")
		@ResponseBody
		public JSONArray zyHsyb(String  arrange_class_date) {
			JSONArray sbShiJian = gs.sbShiJian(arrange_class_date);
			return sbShiJian;
		}
		
		
		
		//<!-- 统计每年门诊处 接诊的人数-->
		@PostMapping("bao-biao")
		@ResponseBody 
		public JSONArray mzCounter(Integer datesj){
			if(datesj==null) {
				Date  dd=new Date();
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
				String dateString = formatter.format(dd);
				Integer aa=Integer.parseInt(dateString);
				JSONArray mzCounter = gs.mzCounter(aa);
				System.out.println(mzCounter);
				return mzCounter;
			}else{
				JSONArray mzCounter = gs.mzCounter(datesj);
				return mzCounter;
			}
		}
	
		//新增科室
		@PostMapping("addks")
		@ResponseBody
		public  String addks(String ksmc,Integer kslb) {
			try {
				if(kslb==1) {
					JSONArray mzaddks = gs.mzaddks(ksmc);
					if(mzaddks.size()>0) {
						return "3";
					}else {
						gs.addks(ksmc,kslb);
						return "1";
					}
				}else {
					JSONArray zyaddks = gs.zyaddks(ksmc);
					if(zyaddks.size()>0) {
						return "4";
					}else {
						gs.addks(ksmc,kslb);
						return "1";
					}
				}
				
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "2";
			}
				
		}
		
		//新增医疗项目
		@PostMapping("ymAdd")
		@ResponseBody
		public  String addylxm(String xmmc,BigDecimal xmje) {
			try {
					JSONArray ymAdd = gs.ymAdd(xmmc);
					if(ymAdd.size()>0) {
						return "3";
					}else {
						gs.addylxm(xmmc,xmje);
						return "1";
					}
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "2";
			}
				
		}
		
		
		//<!-- 查询所有科室 -->
		@RequestMapping("findks")
		@ResponseBody
		public JSONArray findks(String  departments_name) {
			JSONArray findks = gs.findks(departments_name);
			return findks;
		}
		//体检项目新增
		@PostMapping("xzTjxmCx")
		@ResponseBody
		public  String  xzTjxmCx(String examine_item_name,BigDecimal tjxmje) {
			try {
				JSONArray xzTjxmCx = gs.xzTjxmCx(examine_item_name);
				System.out.println("结果"+xzTjxmCx+"名称"+examine_item_name+"金额"+tjxmje);
				if(xzTjxmCx.size()>0) {
					return "3";
				}else {
					gs.addtjxm(examine_item_name, tjxmje);
					return "1";
				}
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return "2";
			}
			
		}
				
		
}
